#!/usr/bin/env bash
## coding=utf-8
##==================================----------==================================
## FILE: lib_shellfuncs
## MYPG: Abodu {gitee: gitee.com/abodu}
## LSCT: 2025-03-10 10:40:23
## VERS: 0.5
##==================================----------==================================

{
  mt_getprompt() {
    local cc= bk="${*}" zl="${ZLANG:-cn}"
    case ${CLR} in
    cred | CRED | [rR] | red) cc="${CRED}" && red_exit=1 ;;
    cblu | CBLU | [bB] | blue) cc="${CBLU}" ;;
    cyan | CYAN | [cC] | cyan) cc="${CYAN}" ;;
    cgrn | CGRN | [gG] | green) cc="${CGRN}" ;;
    cplp | CPLP | [pP] | purple) cc="${CPLP}" ;;
    cylw | CYLW | [yY] | yellow) cc="${CYLW}" ;;
    esac
    ##
    if [[ "X${bk//[a-z0-9_]/}" = "X" ]]; then
      [[ ${bk}X == @(cn|en|jp|fr|ru|de)_*X ]] && bk="${bk#*_}"
      set -- "${GPROMPTS[${zl}_${bk}]}"
      [ ${#1} -ge 1 ] && bk="${*}"
    fi
    printf -- "${cc}${bk}${CEND}" | sed -r 's@^\s+#TDL#@@g'
    ##
    [ X${LSW_NEWLINE:-1} = X1 ] && echo
    [ X1 = X${red_exit} ] && [[ X${0}Z != X*bashZ ]] && exit 1
  }
  ## [COLORS] ##
  mcary=(RED:"31;1" GRN:32 YLW:33 BLU:34 PLP:35 YAN:36 END:0)
  for x in ${mcary[@]}; do
    p=(${x//:/ }) && eval "export C${p[0]}='\e[${p[1]}m'"
  done
  for x in red blue cyan green purple yellow; do
    #   eval "_${x}(){ CLR=${x} mt_getprompt \$@; }"
    eval "_${x}(){ { CLR=${x} mt_getprompt \$@; } 2>/dev/null; }"
  done
  unset -v x p mcary
  ##
  export PFX4SUB='@----> '
  declare -gA GPROMPTS=()
} 2>/dev/null

test_mult_langtip() {
  {
    # 检查系统版本是否符合要求
    GPROMPTS+=(
      [cn_must_likedebian]="本机操作系统不符合要求，需要 Ubuntu 或 Debian 8+"
      [en_must_likedebian]="NOT meet the requirements, Ubuntu or Debian 8+ is required"
      [cn_meet_os_version]="本机操作系统符合要求"
      [en_meet_os_version]="This OS meets the requirements"
    )
  } 2>/dev/null
  
  _green "meet_os_version"
  _yellow "must_likedebian"
}
###测试用例###
test_mult_langtip
ZLANG=en test_mult_langtip
# test_mult_langtip_2
_blue "蓝色提示信息"
_green "绿色提示信息"
_purple "紫色提示信息"
_red "红色提示信息并退出脚本(没有执行后面的语句)"
